//
//  BossMessageCell.m
//  LazyCat
//
//  Created by jike on 16/3/22.
//  Copyright (c) 2016年 zhanshu. All rights reserved.
//

#import "BossMessageCell.h"

@implementation BossMessageCell

- (void)awakeFromNib {
    // Initialization code
}
- (void)setArr:(NSArray *)arr {
    _arr = arr;
}
- (void)setInType:(NSString *)inType {
    _inType = inType;
}
- (void)setContentStr:(NSString *)contentStr {
    _contentStr = contentStr;
}
- (void)drawRect:(CGRect)rect {
    //绘制圆角
    self.backView.layer.borderWidth = 1;
    self.backView.layer.borderColor = SetColor(225, 225, 225, 1).CGColor;
    self.backView.layer.cornerRadius = 5;
    self.backView.clipsToBounds = YES;
    _timeLabel.layer.cornerRadius = 3;
    _timeLabel.clipsToBounds = YES;
    //计算字符串的高度和宽度。。图文混排
    UILabel *contentLabel = [[UILabel alloc]init];
    contentLabel.numberOfLines = 0;
    contentLabel.text = _contentStr;
    contentLabel.font = [UIFont systemFontOfSize:15];
    contentLabel.tag = 111;
    CGSize size = CGSizeMake(ScreenWidth-60, 1000);
    CGSize labelSize = [contentLabel.text sizeWithFont:[UIFont systemFontOfSize:15] constrainedToSize:size lineBreakMode:NSLineBreakByClipping];
    contentLabel.frame = CGRectMake(30, 125, ScreenWidth - 60, labelSize.height);
    NSLog(@"%f,%f",labelSize.width,labelSize.height);
    [self.contentView addSubview:contentLabel];
    //动态创建label
    CGSize SIZE;
    CGSize length1;
    
    for (int i = 0; i < _arr.count; i++) {
        for (int j = 0; j < 2; j++) {
            UILabel *keyLabel = [[UILabel alloc] init];
            
            if (j == 0) {
                keyLabel.text =[NSString stringWithFormat:@"%@ :",[_arr[i] objectForKey:@"key"]];
                keyLabel.textColor = SetColor(153, 153, 153, 1);
            }else if(j == 1){
                keyLabel.text = [_arr[i] objectForKey:@"value"];
                keyLabel.textColor = SetColor(51, 51, 51, 1);

            }
            keyLabel.tag = 111;
            SIZE = [keyLabel.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:keyLabel.font,NSFontAttributeName, nil]];
            if (j == 0) {
                keyLabel.frame = CGRectMake(30 + (SIZE.width ) * j, 140 + 10 +23 * i - 15 + labelSize.height, SIZE.width, SIZE.height);
                length1 = SIZE;
            }else if (j==1){
                keyLabel.frame = CGRectMake(30 + (length1.width) * j, 140 + 10 +23 * i - 15 + labelSize.height, SIZE.width, SIZE.height);
            }
            keyLabel.font = [UIFont systemFontOfSize:13];
            [self.contentView addSubview:keyLabel];
        }
    }
    _timeLabel.frame = CGRectMake((ScreenWidth - 140)/2, _timeLabel.frame.origin.y, _timeLabel.frame.size.width, _timeLabel.frame.size.height);
    //动态布局
    if ([_inType isEqualToString:@"1"] || [_inType isEqualToString:@"2"] || [_inType isEqualToString:@"5"]) {//不显示查看详情
        _lineView2.frame = CGRectMake(_lineView2.frame.origin.x, 80+10 + _arr.count * 23 - 15 + labelSize.height, _lineView2.frame.size.width, _lineView2.frame.size.height);
        _LookLabel.frame = CGRectMake(_LookLabel.frame.origin.x, 80 +10 + _arr.count * 23 - 15 + labelSize.height, _LookLabel.frame.size.width, _LookLabel.frame.size.height);
        _InImageView.frame = CGRectMake((ScreenWidth - 23 - 30), 100 + _arr.count * 23 - 15 + labelSize.height, _InImageView.frame.size.width, _InImageView.frame.size.height);
        _backView.frame = CGRectMake(_backView.frame.origin.x, _backView.frame.origin.y, ScreenWidth - 30,80+ 10+ _arr.count * 23 +35- 15 + labelSize.height);
    }else {
        _backView.frame = CGRectMake(_backView.frame.origin.x, _backView.frame.origin.y, ScreenWidth - 30,80+ 10+ _arr.count * 23 - 15 + labelSize.height);
        _InImageView.hidden = YES;
        _lineView2.hidden = YES;
        _LookLabel.hidden = YES;
    }
    
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
